package com.wantupai.app.httpnet;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * BaseObserver
 * Created by wmq on 2019-05-13.
 */
public abstract class BaseObserver2<T> implements Observer<BaseEntity<T>>{

    private static final String TAG = "BaseObserver2";
    private Context mContext;

    protected BaseObserver2(Activity context) {
        this.mContext = context.getApplicationContext();
    }

    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(BaseEntity<T> value) {

        if (value.isSuccess()) {
            T t = value.getData();
            onHandleSuccess(t);
        } else {
            onHandleError(value.getMsg());

        }
    }

    @Override
    public void onError(Throwable e) {
        Log.e(TAG, "onError:" + e.toString());

    }

    @Override
    public void onComplete() {
//        Log.d(TAG, "onComplete");
//        if (mAnimationView != null && mAnimationView.isAnimating()) {
//            mAnimationView.cancelAnimation();
//        }
    }

   // protected abstract void onHandleSuccess(T t);


    protected void onHandleSuccess(T t){

    }


    protected void onHandleError(String msg) {
        Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
//        CustomToast.showToast(mContext, msg+"!");
    }
}
